<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/2 0002
 * Time: 下午 2:37
 */

namespace app\home\controller;
use app\home\model\Country as CountryModel;
use app\home\model\Like;
use app\home\model\Comment;
class Country extends Base
{
    /**首页
     * @return mixed
     */
    public function index(){
        //验证权限
        $this->anonymous();
        $Model = new CountryModel();
        $list1 = $Model->getList(1);
        $list2 = $Model->getList(2);
        $list3 = $Model->getList(3);
        $this->assign([
            'list1'=>$list1,
            'list2'=>$list2,
            'list3'=>$list3,
        ]);
        return $this->fetch();
    }

    /*
     详情页
    */
    public function detail(){
        //验证权限
        $this->anonymous();
        $Model = new CountryModel();
        $id = input('id');
        $userId = session('userId');
        //新增浏览量
        $Model->setView($id);
        $detail = $Model->get($id);
        //获取点赞
        $likeModel = new Like();
        $like = $likeModel->getLike(3,$id,$userId);
        $detail['is_like'] = $like;
        //获取评论
        $commentModel = new Comment();
        $comment = $commentModel->getComment(3,$id,$userId);
        $this->assign([
            'detail'=>$detail,
            'comment'=>$comment,
        ]);
        return $this->fetch();
    }

    /**
     * 下拉加载
     */
    public function listMore(){
        $Model = new CountryModel();
        $type = input('type');
        $length = input('length');
        $list = $Model->getList($type,$length);
        if($list) {
            return $this->success("加载更多","",$list);
        }else{
            return $this->error("加载失败");
        }
    }
}